require 'rexml/document'
require 'c:/tools/kronos/ruby/line'

class PseudoState

  attr_accessor :nameU
  attr_accessor :type
  attr_accessor :end_nameU
  attr_accessor :end_name
	attr_accessor :merge_statement

  def initialize( xml_doc )

    @nameU     = xml_doc.attributes["NameU"]
    @end_nameU = xml_doc.elements["Control"].elements["X"].attributes["F"]
    @type      = xml_doc.elements["Control"].elements["Prompt"].text

		@merge_statement = Hash.new
		@merge_statement = nil

    stripEnd

  end

  def stripEnd

    position = @end_nameU.index '\''
    @end_nameU.slice!(0..position)

    position = @end_nameU.index '\''
    @end_nameU = @end_nameU.slice!(0..(position - 1))
    
  end

  def consolidatePseudostateNames( states, lines )

    @end_name = @end_nameU

    states.each { |state|
      if @end_nameU == state.nameU
        @end_name = state.name
				return
      end
    }

		lines.each { | line |
			if @end_nameU == line.start_nameU

				dummy_line = Line.new( nil )
				dummy_line.end_nameU = @end_nameU
				
				@merge_statement = Line.recursiveMergeConsolidation( dummy_line, states, lines )
				return
			end
		}

  end

end


